package com.uking.moudle;

import com.smalls.newvideotwo.util.LogUtil;
import com.uking.ukingmodule.ukingjnic;
import com.uking.ukingmodule.ukingjnic.onStateChangeLisenser;
import com.uking.util.VKConstant;

public class PlayerJniImple implements PlayerJniInterface {
    private onStateChangeLisenser mLisener;


    public PlayerJniImple(onStateChangeLisenser lisenser) {
        this.mLisener = lisenser;
    }

    public int onInit(int type, int playport) {

        ukingjnic.getInstance().setonStateChangeLisenser(this.mLisener);
        return 1;
    }

    public boolean hasAuth(int type, String authserver, String code, String authString) {
        String result = ukingjnic.getInstance().playCodeAuthentication(type, code);
        if (result!=null&&result.contains("CODE=0")) {
            return true;
        }
        return false;
    }

    public String registerUser(String authserver, String pagekageName, String sn, String username, String password) {
        return ukingjnic.getInstance().registerUser(authserver, pagekageName, sn);
    }

    public int onDoWork(int type, String code) {

        String result;
        if(VKConstant.B_ENABLE_HLS_MODE) {

            result = ukingjnic.getInstance().startGetPlayURL(type, code);
            LogUtil.i("PlayerJniImple", "onDoWork startGetPlayURL result=" + result);
        }else {
            result = ukingjnic.getInstance().startDownload(type, code);
            LogUtil.i("PlayerJniImple", "onDoWork startDownload result=" + result);
        }
        if (result!=null&&result.contains("CODE=0")) {
            return 1;
        }
        return -1;
    }

    public int onDestroy(int type) {
        String result = ukingjnic.getInstance().stopDownload(type);
        if (result!=null&&result.contains("CODE=0")) {
            return 1;
        }
        return -1;
    }

    public int onDestoryDlownloadModul(int type) {
        String result = ukingjnic.getInstance().destroyDlownloadModul(type);
        if (result!=null&&result.contains("CODE=0")) {
            return 1;
        }
        return -1;
    }

    public int initDownloadModul(int type, int playport) {
        String result = ukingjnic.getInstance().initDownloadModul(type, playport);
        LogUtil.i("PlayerJniImple","initDownloadModul initDownloadModul result="+result);
        if (result!=null) {
            if(result.contains("CODE=0")) {
                return 1;
            }
//            if(result.contains("CODE=30002")) {
//                return 1;
//            }
            return -1;
        }
        return -1;
    }
}
